<HTML>
<HEAD>
<TITLE> Converting and Porting SPICE Binary Data Files </TITLE>
</HEAD>

<BODY style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">

<A NAME="top"></A>

<TABLE STYLE="text-align: left; margin-left: auto; margin-right: auto; width: 800px;" BORDER="0" CELLPADDING="5" CELLSPACING="2">
<TBODY>
<TR>
  <TD STYLE="background-color: rgb(153, 153, 153); vertical-align: middle; text-align: center;">
  <DIV ALIGN="right">
    <SMALL><SMALL><A HREF="index.html">Index Page</A></SMALL></SMALL>
  </DIV>
  <B>Converting and Porting SPICE Binary Data Files</B> </TD>
</TR>
<TR>
  <TD STYLE="vertical-align: top;">

<H2> Table of Contents
</H2>

<PRE>
   <A HREF="#Converting and Porting SPICE Binary Data Files">Converting and Porting SPICE Binary Data Files</A>
      <A HREF="#Abstract">Abstract</A>
      <A HREF="#Revisions">Revisions</A>
      <A HREF="#Introduction">Introduction</A>
      <A HREF="#Binary File Format">Binary File Format</A>
      <A HREF="#Reading Non-native Binary Data Files">Reading Non-native Binary Data Files</A>
      <A HREF="#Restrictions on Using Non-native Binary Data Files">Restrictions on Using Non-native Binary Data Files</A>
   <A HREF="#Utility Programs for Porting SPICE Files.">Utility Programs for Porting SPICE Files.</A>
      <A HREF="#The Two Conversion Methods">The Two Conversion Methods</A>
         <A HREF="#TOBIN and TOXFR -- Command Line Based File Conversion.">TOBIN and TOXFR -- Command Line Based File Conversion.</A>
         <A HREF="#Examples Using TOBIN and TOXFR.">Examples Using TOBIN and TOXFR.</A>
         <A HREF="#SPACIT -- Interactive File Conversion.">SPACIT -- Interactive File Conversion.</A>

</PRE>

<HR SIZE=3 NOSHADE>

<BR><BR>
<A NAME="Converting and Porting SPICE Binary Data Files"></A>
<p align="right"><a href="#top"><small>Top</small></a></p>
<H1> Converting and Porting SPICE Binary Data Files
</H1><HR SIZE=3 NOSHADE><P><BR><BR><BR>
   Last revised on 2002 JAN 13 by F. S. Turner.
<P>
 
<BR><BR>
<A NAME="Abstract"></A>
<p align="right"><a href="#top"><small>Top</small></a></p>
<H2> Abstract
</H2><HR ALIGN="LEFT" WIDTH=50% ><P><BR><BR>
   SPICE provides a mechanism and a set of utilities to facilitate moving
   SPICE binary data files from one computing environment to another.
<P>
 
<BR><BR>
<A NAME="Revisions"></A>
<p align="right"><a href="#top"><small>Top</small></a></p>
<H2> Revisions
</H2><HR ALIGN="LEFT" WIDTH=50% ><P><BR><BR>
   January 13, 2002
<P>
 
<UL>
<TT>&#32;&#32;</TT> The contents of this guide were extensively revised to reflect the
inclusion of the DAF run-time binary file format translation capability
into the SPICE toolkit.
<BR><BR></UL>
<BR><BR>
<A NAME="Introduction"></A>
<p align="right"><a href="#top"><small>Top</small></a></p>
<H2> Introduction
</H2><HR ALIGN="LEFT" WIDTH=50% ><P><BR><BR>
   This document describes issues related to moving SPICE binary data files
   from one computing environment to another. Often a SPICE data file (or
   kernel) is generated within one particular environment for use in
   another. NAIF has developed software that allows users to read binary
   SPICE data files generated on most supported platforms by simply
   transferring the file directly. In a few cases, ``transfer format''
   software, available in the SPICE Toolkit, must be used. The remainder of
   this document discusses when binary kernels may be exchanged directly,
   what restrictions exist in using files from other computing
   environments, and the mechanisms for exchanging data with users of
   environments that do not support this capability.
<P>
 
<BR><BR>
<A NAME="Binary File Format"></A>
<p align="right"><a href="#top"><small>Top</small></a></p>
<H2> Binary File Format
</H2><HR ALIGN="LEFT" WIDTH=50% ><P><BR><BR>
   SPICE binary data files are Fortran direct access unformatted files,
   i.e., they contain data in a raw binary form. The specifics of this
   form, henceforth referred to as binary file format, are determined by
   characteristics of the computing environment used to generate the file.
   Factors such as word size and floating point representation control
   exactly how raw data are placed into the file at the byte level.
   Computing environments that share the same binary file format may freely
   exchange SPICE binary data files as though the original files were
   produced in their environment. Files whose binary file format agrees
   with the local computing environment are referred to as native format
   files, or just native files. Similiarly those whose format disagrees,
   are commonly referred to as non-native.
<P>
 
   The collection of computing environments for which SPICE toolkits exist
   (often called supported environments) utilize four distinct binary file
   formats: Big Endian IEEE, Little Endian IEEE, Vax D-Floating, and Vax
   G-Floating. The breakdown by computing environment is as follows:
<P>
 
<PRE>
 
   Big Endian IEEE:
   ---------------
      HP:
         HP Fortran, HP C
      Macintosh:
         Absoft Fortran, Metrowerks Codewarrior C
      SGI:
         N32/O32 Fortran, MIPS C (N32/O32 ABIs)
      Sun:
         Solaris Fortran, Solaris Native C, Solaris GCC
 
   Little Endian IEEE:
   ------------------
      PC:
         Linux G77, Compaq Visual Fortran, Lahey Fortran 95,
         Linux GCC, Microsoft Visual C++
      Alpha (Digital Unix):
         Digital Fortran, Digital C
 
   Vax D-Floating:
   --------------
      Alpha (VMS):
         Digital Fortran
      VAX:
         Digital Fortran
 
   Vax G-Floating:
   --------------
      Alpha (VMS):
         Digital Fortran
 
</PRE>
   For example, a SPICE binary data file generated on an HP using Fortran
   can be moved directly to a Sun using CSPICE with the native C compiler
   (or for that matter any supported compiler). As the table above
   illustrates, these systems utilize the same binary file format, making
   such an exchange possible.
<P>
 
<BR><BR>
<A NAME="Reading Non-native Binary Data Files"></A>
<p align="right"><a href="#top"><small>Top</small></a></p>
<H2> Reading Non-native Binary Data Files
</H2><HR ALIGN="LEFT" WIDTH=50% ><P><BR><BR>
   The preceding section implies that users of computing environments
   utilizing dissimiliar binary file formats may not exchange binary files
   directly. In general this is true, however, the Toolkit software on most
   supported computing environments includes a run-time binary file format
   translation, or binary translation, capability. This enables these
   computing environments to read some non-native binary files, with some
   restrictions noted in the section that follows.
<P>
 
   The diagram below illustrates which computing environments are capable
   of reading non-native files. The arrows in the diagram indicate the
   direction in which the files may be exchanged.
<P>
 
<PRE>
 
    ----------              ----------
   | Big      |-----------&gt;| Little   |
   | Endian   |            | Endian   |
   | IEEE     |&lt;-----------| IEEE     |
    ----------              ----------
 
 
    ----------              ----------
   | Vax      |            | Vax      |
   | D-       |            | G-       |
   | Floating |            | Floating |
    ----------              ----------
 
</PRE>
   As the above diagram illustrates, any Big Endian IEEE supported
   computing environment is able to read binary files generated on Little
   Endian IEEE environments. The reverse is also true, namely that Little
   Endian IEEE environments are capable of reading binary files produced on
   Big Endian IEEE environments.
<P>
 
   However, users on these systems may not read binaries produced in either
   Vax D-Floating or Vax G-Floating environments. For file exchange between
   these environments the SPICE Toolkit provides the mechanisms discussed
   in the following chapter, using the ``SPICE Transfer format.''
<P>
 
<BR><BR>
<A NAME="Restrictions on Using Non-native Binary Data Files"></A>
<p align="right"><a href="#top"><small>Top</small></a></p>
<H2> Restrictions on Using Non-native Binary Data Files
</H2><HR ALIGN="LEFT" WIDTH=50% ><P><BR><BR>
   The binary translation capability provides access to non-native binary
   files on most supported environments. However, there are several
   restrictions that require noting:
<P>
 
<UL>
<TT>--</TT> As of Toolkit Version N0052 this capability is implemented only for DAF
based files (SPK, CK, and binary PCK). Users of E-kernels and other DAS
based kernels will need to await a future release of the toolkit before
this capability is extended to these files.
<BR><BR></UL>
<UL>
<TT>--</TT> The binary translation capability provides ``read-only'' access to
non-native binary files. Attempts to add, alter, or remove comments from
non-native binary files (using tools such as COMMNT) will fail. Also,
appending or altering the data contents of non-native binary files (using
MKSPK or other mission specific tools) will also fail.
<BR><BR></UL>
<UL>
<TT>--</TT> Using non-native files may impact the performance of SPICE based
applications. The impact is highly dependent on the particular computing
environment and the usage scenario. Typically the decrease is somewhere
between 5 and 10 percent, but may be as large as a factor of 2 or 3 for
highly read intensive scenarios.
<BR><BR></UL>
   If the ``read-only'' nature of access or the performance degradation are
   issues, then converting the non-native binary files into native format
   is recommended. This can be accomplished using TOBIN and TOXFR (tools
   included in the SPICE Toolkit) in the following fashion:
<P>
 
   First convert the non-native binary to transfer format using TOXFR:
<P>
 
<PRE>
    &gt; toxfr non-native.bsp transfer.xsp
</PRE>
   Then convert the transfer format file to native binary format using
   TOBIN:
<P>
 
<PRE>
    &gt; tobin transfer.xsp native.bsp
</PRE>
   TOXFR, on environments that support binary translation, can create
   transfer files from the supported non-native binary file formats. For
   example, TOXFR on a Sun can make a transfer format file from a PC
   binary. However, the same version of TOXFR may not make a transfer
   format file from any file originating from either of the Vax formats.
<P>
 
<BR><BR>
<A NAME="Utility Programs for Porting SPICE Files."></A>
<p align="right"><a href="#top"><small>Top</small></a></p>
<H1> Utility Programs for Porting SPICE Files.
</H1><HR SIZE=3 NOSHADE><P><BR><BR><BR>
   If it is the case that one of the computing environments generating or
   using files is not supported for binary translation, several tools are
   delivered with the SPICE Toolkit to address this issue.
<P>
 
   In these situations, the portability of SPICE binary data files is
   achieved by using an intermediate file called a ``transfer'' file. A
   transfer file contains an environment independent representation of the
   data from a binary SPICE file that consists only of ASCII characters,
   and hence is easily moved from one computing environment to another.
   There are three steps involved in moving the information in a SPICE
   binary data file from a host, or originating, computing environment to a
   target, or destination, computing environment.
<P>
 
<UL>
<TT>1.</TT> Convert the SPICE binary data file into the environment independent
transfer file in the host computing environment. The utility programs
described later in this document provide this capability.
<BR><BR></UL>
<UL>
<TT>2.</TT> Move the environment independent transfer file to the target computing
environment. (Typically using ASCII mode of FTP).
<BR><BR></UL>
<UL>
<TT>3.</TT> Convert the environment independent transfer file into a SPICE binary data
file in the target computing environment. The utility programs described
later in this document provide this capability.
<BR><BR></UL>
<BR><BR>
<A NAME="The Two Conversion Methods"></A>
<p align="right"><a href="#top"><small>Top</small></a></p>
<H2> The Two Conversion Methods
</H2><HR ALIGN="LEFT" WIDTH=50% ><P><BR><BR>
   There are two methods for converting SPICE data files from one of their
   formats to the other; an interactive method and a command line, ``or
   batch,'' method. The interactive method makes use of the SPICE Toolkit
   utility program SPACIT, and the command line method makes use of the
   SPICE Toolkit utility programs TOXFR and TOBIN which convert files from
   the binary format to the transfer format and from the transfer format to
   the binary format, respectively. (Using TOXFR and TOBIN is usually
   faster than using SPACIT.)
<P>
 
<BR><BR>
<A NAME="TOBIN and TOXFR -- Command Line Based File Conversion."></A>
<p align="right"><a href="#top"><small>Top</small></a></p>
<H3> TOBIN and TOXFR -- Command Line Based File Conversion.
</H3><P><BR><BR>
   The utility programs TOBIN and TOXFR provide a command line, or
   ``batch,'' oriented method for converting portable transfer files into
   SPICE binary kernel files and converting SPICE binary kernel files into
   portable transfer files, respectively. The name ``tobin'' is obviously
   derived from ``to binary,'' as in ``convert to binary''. The name
   ``toxfr'' is, possibly not so obviously, derived from ``to transfer,''
   as in ``convert to transfer.''
<P>
 
   TOBIN converts a SPICE transfer format file into it's binary format for
   use in a particular computing environment. TOBIN requires at least the
   name of the input transfer file, which is the first argument on the
   command line. Optionally, a name for the output binary file may be
   specified as the second argument on the command line. If a name for the
   output file is provided it overrides the automatic naming conventions
   used by the program.
<P>
 
   If only the name of the input transfer file is provided on the command
   line, TOBIN will generate a name for the output binary kernel file that
   has the same base name as the input transfer file and an appropriate
   filename extension, based on the filename extension of the transfer
   file. If TOBIN does not recognize the filename extension of the input
   transfer file, or there is no filename extension on the input transfer
   file, a filename extension of '.bin' will be used as the filename
   extension of the output binary file. If a file having the same name as
   the output file already exists, TOBIN signals an error and stops. We
   assume that it is bad form to overwrite or replace an existing file.
<P>
 
   TOBIN recognizes the transfer filename extensions ``.xc'', ``.xee'',
   ``.xpc'', and ``.xsp'' associated with transfer files for SPICE data
   products. These are converted to the SPICE binary kernel filename
   extensions ``.bc'', ``.bee'', ``.bpc'', and ``.bsp,'' respectively. Also
   recognized are the old transfer file extensions ``.tc'', ``.tee'',
   ``.tpc'', and ``.tsp,'' which are converted into the appropriate
   filename extensions for a binary kernel file.
<P>
 
   TOXFR converts a SPICE binary kernel file into a transfer file format
   that is used to transfer, or port, the binary data to a different
   computing environment. TOXFR requires at least the name of the input
   binary file, which is the first argument on the command line.
   Optionally, a name for the output transfer file may be specified as the
   second argument on the command line. If a name for the output file is
   provided on the command line it overrides the automatic naming
   conventions used by the program.
<P>
 
   If only the name of the input binary file is provided on the command
   line, TOXFR will generate a name for the output transfer file that has
   the same base name as the input binary file and an appropriate filename
   extension, based on the filename extension of the binary file. If TOXFR
   does not recognize the filename extension of the input binary file, or
   there is no filename extension on the input binary file, a filename
   extension of '.xfr' will be used as the filename extension of the output
   transfer file. If a file having the same name as the output file already
   exists, TOXFR signals an error and stops. Again, we assume that it is
   bad form to overwrite or replace an existing file.
<P>
 
   TOXFR recognizes the filename extensions ``.bc'', ``.bee'', ``.bpc'',
   and ``.bsp'' which are associated with SPICE binary kernel files. These
   are converted to the transfer filename extensions ``.xc'', ``.xee'',
   ``.xpc'', and ``.xsp,'' respectively.
<P>
 
   As mentioned previously, it my not be necessary to convert a SPICE
   binary kernel file into the transfer file format when moving the data
   from one computing environment to another. If the binary file formats in
   each of the computing environments are identical, the same binary file
   may be used without modification. The direct exchange of SPICE binary
   kernel files is known to work when moving the files among Sun
   Sparcstation, HP 9000, SGI, and Macintosh computing environments. This
   is possible because they all use standard UNIX file formats and IEEE
   representations for floating point numbers.
<P>
 
<BR><BR>
<A NAME="Examples Using TOBIN and TOXFR."></A>
<p align="right"><a href="#top"><small>Top</small></a></p>
<H3> Examples Using TOBIN and TOXFR.
</H3><P><BR><BR>
   TOBIN and TOXFR each require the name of the file to be converted and,
   optionally, the name of the file to be produced, e.g.,
<P>
 
<PRE>
   prompt &gt; tobin thisfile.xsp
</PRE>
   and
<P>
 
<PRE>
   prompt &gt; tobin thisfile.xsp thisfile.bsp
</PRE>
   would both produce the file `thisfile.bsp' in the current directory.
<P>
 
   In the first example, the name for the binary file produced is derived
   from the name of the transfer file, using the full base name and
   replacing the letter `x' in the file name extension with the letter `b',
   to indicate that the file is a binary file. In the second example, the
   name for the binary file produced is taken directly from the command
   line.
<P>
 
<UL>
<TT>--</TT> Example 1: Convert the transfer file 'ephem.xsp' into a binary kernel file.
<BR><BR></UL>
<PRE>
    &gt; tobin ephem.xsp
</PRE>
<UL>
<TT>&#32;&#32;</TT> This will create the binary kernel file 'ephem.bsp'.
<BR><BR></UL>
<UL>
<TT>--</TT> Example 2: This is the same as Example 1, except we explicitly set the
output filename on the command line.
<BR><BR></UL>
<PRE>
    &gt; tobin ephem.xsp myephem.bsp
</PRE>
<UL>
<TT>&#32;&#32;</TT> This will create the binary kernel file 'myephem.bsp'.
<BR><BR></UL>
<UL>
<TT>--</TT> Example 3: For this example, we provide a filename extension on the input
transfer file that TOBIN does not recognize.
<BR><BR></UL>
<PRE>
    &gt; tobin mydata.ttt
</PRE>
<UL>
<TT>&#32;&#32;</TT> This will create the binary file 'mydata.bin'.
<BR><BR></UL>
<UL>
<TT>--</TT> Example 4: Convert the binary kernel file 'ephem.bsp' into a transfer file.
<BR><BR></UL>
<PRE>
    &gt; toxfr ephem.bsp
</PRE>
<UL>
<TT>&#32;&#32;</TT> This will create the transfer file 'ephem.xsp'.
<BR><BR></UL>
<UL>
<TT>--</TT> Example 5: This is the same as Example 1, except we explicitly set the
output filename on the command line.
<BR><BR></UL>
<PRE>
    &gt; toxfr ephem.bsp myephem.xsp
</PRE>
<UL>
<TT>&#32;&#32;</TT> This will create the transfer file 'myephem.bsp'.
<BR><BR></UL>
<UL>
<TT>--</TT> Example 6: For this example, we provide a filename extension on the input
binary file that TOXFR does not recognize.
<BR><BR></UL>
<PRE>
    &gt; toxfr mydata.bbb
</PRE>
<UL>
<TT>&#32;&#32;</TT> This will create the transfer file 'mydata.xfr'.
<BR><BR></UL>
<BR><BR>
<A NAME="SPACIT -- Interactive File Conversion."></A>
<p align="right"><a href="#top"><small>Top</small></a></p>
<H3> SPACIT -- Interactive File Conversion.
</H3><P><BR><BR>
   The SPACIT utility program is an interactive, menu driven program that
   provides a file conversion capability, among other things. The SPACIT
   main menu has an option for converting a SPICE binary kernel file into a
   portable transfer file, and an option for converting a transfer file
   into a binary kernel file.
<P>
 
<PRE>
            SPACIT Options
 
      ( Q ) Quit.
      ( L ) Log SPACIT output to a file.
      ( T ) Convert transfer file to binary file.
      ( B ) Convert binary file to transfer file.
      ( S ) Summarize binary file.
      ( R ) Read comment area of binary file.
 
      Option:
</PRE>
   To convert a SPICE binary kernel file into a portable transfer file,
   select option `B' from the SPACIT main menu. Prompts for the input and
   output filenames will be given, and then the binary kernel file will be
   converted. Similarly, to convert a portable transfer file into a SPICE
   binary kernel file, select option `T' from the SPACIT main menu.
<P>
 
   Please see the SPACIT User's Guide, <a href="../ug/spacit.html">spacit.ug</a>, for complete details on
   the use of this program.
<P>
 

</TD>
</TR>
</TBODY>
</TABLE>

</BODY>

</HTML>
